#include "Utils.hh"
#include "BankSystem.hh"
#include "Account.hh"
#include "8_PerformTransfer.hh"
#include "9_ViewTransactionHistory.hh"
#include "6_PerformDeposit.hh"
#include "7_PerformWithdrawal.hh"

using namespace BankSystem;
// 账户菜单
void showAccountMenu(BankSystem::BankSystem& bankSystem, const std::shared_ptr<Account>& account) {
    while (true) {
        SetConsoleOutputCP(CP_UTF8);
        system("clear");
        
        std::cout << "===== Bank Account: " << account->getAccountId() << " (" << account->getAccountType() << ") =====" << std::endl;
        std::cout << "Account holder: " << account->getCustomerName() << std::endl;
        std::cout << "Balance: " << Utils::formatCurrency(account->getBalance()) << "\n" << std::endl;
        
        // 根据账户类型显示不同的选项
        bool isSavings = (account->getAccountType() == "Savings Account");
        
        int option = 1;
        if (!isSavings) {
            std::cout << option++ << ". Deposit" << std::endl;
            std::cout << option++ << ". Withdraw" << std::endl;
        }
        
        std::cout << option++ << ". Transfer" << std::endl;
        std::cout << option++ << ". View transaction history" << std::endl;
        std::cout << option++ << ". Generate bank account report" << std::endl;
        std::cout << option++ << ". Return to customer page" << std::endl;
        
        std::cout << "\nPlease choose: ";
        
        int choice;
        std::cin >> choice;
        clearInputBuffer();
        
        // 根据账户类型调整选项
        if (isSavings) {
            // 储蓄账户菜单
            switch (choice) {
                case 1:
                    performTransfer(bankSystem, account);
                    break;
                case 2:
                    viewTransactionHistory(account);
                    break;
                case 3:
                    account->generateReport();
                    waitForEnter();
                    break;
                case 4:
                    return;
                default:
                    std::cout << "Invalid choice. Please try again." << std::endl;
                    waitForEnter();
            }
        } else {
            // 支票账户菜单
            auto checkingAccount = std::dynamic_pointer_cast<CheckingAccount>(account);
            
            switch (choice) {
                case 1:
                    performDeposit(checkingAccount);
                    break;
                case 2:
                    performWithdrawal(checkingAccount);
                    break;
                case 3:
                    performTransfer(bankSystem, account);
                    break;
                case 4:
                    viewTransactionHistory(account);
                    break;
                case 5:
                    account->generateReport();
                    waitForEnter();
                    break;
                case 6:
                    return;
                default:
                    std::cout << "Invalid choice. Please try again." << std::endl;
                    waitForEnter();
            }
        }
    }
}
